package com.example.performance.jmh.annotation;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

/**
 * @author zpMeng
 * @since 9/18/2024
 */
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 3, time = 1)
@Threads(2)
@Fork(1)
public class A7CompilerControl {
    @Benchmark
    public void baseline() {
    }

    @Benchmark
    public void blank() {
        targetBlank();
    }

    public void targetBlank() {
    }

    @Benchmark
    public void dontInline() {
        targetDontInline();
    }

    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
    public void targetDontInline() {
    }

    @Benchmark
    public void inline() {
        targetInline();
    }

    @CompilerControl(CompilerControl.Mode.INLINE)
    public void targetInline() {
    }

    @Benchmark
    public void exclude() {
        targetExclude();
    }

    @CompilerControl(CompilerControl.Mode.EXCLUDE)
    public void targetExclude() {
    }

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder().include(A7CompilerControl.class.getSimpleName())
                .build();
        new Runner(options).run();
    }
}
